﻿Imports Cognex.VisionPro
Imports System.Net.Sockets
Imports System.Runtime.InteropServices
Imports CommonDLL.Common

Module GlobalVar
#Region "加密狗参数信息"
    Public Class JDKEY_DEFINE
        Public Const DONGLE_SUCCESS As UInteger = 0        ' 操作成功
        Public Const DONGLE_NOT_FOUND As UInteger = 2147483649        ' 未找到指定的加密机
        Public Const DONGLE_NOT_OPEN As UInteger = 2147483650        ' 尚未打开加密机
        Public Const DONGLE_INVALID_PARAMETER As UInteger = 2147483651        ' 参数错误
        Public Const DONGLE_FAILED As UInteger = 2147483652        ' 操作失败
        Public Const DONGLE_NOT_SUPPORT As UInteger = 2147483653        ' 操作不支持
        Public Const DONGLE_RUN_APP_ERROR As UInteger = 2147483654        ' 运行APP错误
        Public Const DONGLE_SESSIONKEY_FAILED As UInteger = 2147483655        ' 协商通信密钥失败
        Public Const DONGLE_SESSIONKEY_NOT_GEN As UInteger = 2147483656        ' 尚未协商通信密钥
        Public Const DONGLE_SESSIONKEY_FULL As UInteger = 2147483657        ' 会话密钥己满
        Public Const DONGLE_ADMINPIN_NOT_CHECK As UInteger = 2147483658     ' 管理员密码没有验证
        Public Const DONGLE_USERPIN_NOT_CHECK As UInteger = 2147483659        ' 用户密码没有验证
        Public Const DONGLE_PIN_BLOCKED As UInteger = 2147483660        ' PIN码已锁死
        Public Const DONGLE_INCORRECT_PIN As UInteger = 2147483661        ' PIN码错误
        Public Const DONGLE_FILE_EXIST As UInteger = 2147483662        ' 文件已存在
        Public Const DONGLE_FILE_NOT_FOUND As UInteger = 2147483663        ' 未找到指定的文件
        Public Const DONGLE_FILE_READ_ERROR As UInteger = 2147483664        ' 读取文件错误
        Public Const DONGLE_FILE_WRITE_ERROR As UInteger = 2147483665        ' 写入文件错误
        Public Const DONGLE_COMM_ERROR As UInteger = 2147483666        ' 通讯错误
        Public Const DONGLE_ERROR_UNKNOWN As UInteger = 4294967295        ' 未知的错误
    End Class
    '加密锁信息
    <StructLayout(LayoutKind.Sequential)>
    Public Structure DONGLE_INFO
        Public m_Ver_Hardware As UInteger      '硬件版本 (Bit0指示是否带硬时钟)
        Public m_Ver_Firmware As UInteger      '固件版本
        Public m_RealTime_UTC As UInteger      'UTC实时钟
        Public m_ProductID As UInteger         '产品ID	
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=16)>
        Public m_HardSN() As Byte            '16字节的硬件SN
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=6)>
        Public m_BirthDay() As Byte          '出厂时间
    End Structure

    'RSA私钥格式(兼容1024,2048)
    <StructLayout(LayoutKind.Sequential)>
    Public Structure RSA_PRIVATE_KEY
        Public bits As UInteger      'length in bits of modulus   
        Public modulus As UInteger      'modulus
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)>
        Public publicExponent() As Byte            'public exponent
        <MarshalAs(UnmanagedType.ByValArray, SizeConst:=256)>
        Public exponent() As Byte          'public exponent
    End Structure
    Public Class CloseState
        Public Timeout As Integer
        Public Caption As String
        Public Sub New(cap As String, time As Integer)
            Timeout = time
            Caption = cap
        End Sub
    End Class
    Public FlagNum1 As Integer = 0
    Public FlagNum2 As Integer = 0
    Public CheckNum As Integer = 5
    Public mjm As String = "Py7FawlU0xuKyKKpstHrBA=="
#End Region

    Public Structure offset
        Public x As Double  'X偏移
        Public y As Double  'Y偏移
        Public r As Double '角度偏移
        Public IsPass As Boolean '是否OK
        Public ErrCode As Integer '如果有错误，返回错误代码，如果没有则是0
    End Structure
    Public Enum ERRCODE
        Ok = 1
        NG = 2
        Err = 3
    End Enum
    Public Structure Point_Para
        Public torque As Double '扭力
        Public angle As Double  '角度
        Public feeder As Integer '供料器
        Public diable As Boolean '是否禁用
    End Structure
    Public Structure MITSUBISHI_Point
        Public X As Double
        Public Y As Double
        Public Z As Double
        Public A As Double
        Public B As Double
        Public C As Double
        Public L1 As Integer
        Public L2 As Integer
        Public FLG1 As Integer '左右手姿态
        Public FLG2 As Integer
        Public Function PtoString()
            Dim str1 As String
            str1 = "(" & X & "," & Y & "," & Z & "," & A & "," & B & "," & C & "," & L1 & "," & L2 & ")(" & FLG1 & "," & FLG2 & ")"
            Return str1
        End Function
    End Structure

    ' 常量
    Public Const Cam_num As Integer = 4 '支持的相机数量

    Public Const Cam1_trig = 0 '相机1触发点位
    Public Const Cam2_trig = 1 '相机2触发点位
    Public Const Cam3_trig = 2 '相机3触发点位
    Public Const Cam4_trig = 3 '相机4触发点位

    '系统参数
    Public strPassWord As String '登陆密码
    Public week As Integer '星期几
    Public gWarningMsg As String
    Public gIsModBus As Boolean
    Public gIsRun As Boolean '运行中表示
    Public gCheckIndex As Integer
    '统计值
    Public gTrigIndex As Integer
    Public gTotalNumCam(Cam_num - 1) As Integer '检测总数-每个相机单独统计
    Public gPassNumCam(Cam_num - 1) As Integer 'Pass数量-每个相机单独统计
    Public gTotalNum As Integer  '检测总数
    Public gPassNum As Integer  'Pass数量

    '登陆参数
    Public gPriority As Integer '权限
    Public gEngineerPwd As String '工程师密码，默认123
    Public gAdminPwd As String '管理员密码，默认XC
    Public MouseMove_X As Integer
    Public MouseMove_Y As Integer
    Public MouseMove2_X As Integer
    Public MouseMove2_Y As Integer
    'io
    Public gIOCard As Integer 'IO卡编号
    Public Di_Data As Integer '当前输入值
    Public Di_Data_Last As Integer '上一次输入值，以便于当前输入值比较判断上升沿下降沿
    '图像处理参数
    Public fifo(Cam_num - 1) As CogAcqFifoTool '相机
    '  Public gTBPos(Cam_num - 1) As CogToolBlock '定位工具
    Public gTBCheck(Cam_num - 1) As CogToolBlock '检查工具
    Public gPosResult(Cam_num - 1) As offset '输出的XYR偏移量
    ' Public gComRecvData(Cam_num - 1) As String 'com口接收的数据
    '线程控制
    Public mut As New Threading.Mutex() '互斥事件，写入文件的互斥
    Public mutCount As New Threading.Mutex() '互斥事件，产品计数的互斥
    Public mutSp1 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp2 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp3 As New Threading.Mutex() '互斥事件，串口通讯的互斥
    Public mutSp4 As New Threading.Mutex() '互斥事件，串口通讯的互斥

    '产品参数
    Public gCurrProName As String
    Public gUserTime As Integer
    Public gProDataPath As String
    Public gVisionFailedPath As String

    Public PointPara(30) As Point_Para
    Public PointPass(30) As MITSUBISHI_Point
    Public PointWay(30) As Double
    Public Point_X轴C(30) As Double
    Public Point_Y轴C(30) As Double
    Public PointHigh(30) As Double

    '新增参数
    Public StartDlyTime As Long = 0 '开启启动延时
    Public IDLETime As Long = 0 '判IDLE时间
    Public AddProdflag As Boolean = False
    Public AddProdflag1 As Boolean = False
    Public ResultShow_flag As Boolean '锁附结果显示启用/禁用
    Public RobotPanel_flag As Boolean '机器人控制面板显示启用/禁用
    Public Guide_flag As Boolean '产品新建向导启用/禁用

    '拓展功能保存
    Public Photo3_flag As Boolean '第三个拍照点启用标志
    Public KESU As Integer        '第三拍照点启用后可数。
    Public Online_Mod As Integer        '联机方式
    Public suofu_Mod As Integer = 1     '锁付模组 平锁模组或者斜锁模组
    Public PhotoPY As Double        '模板平移距离
    Public PhotoPY_flag As Boolean   '模板平移标志
    Public SN2Check As Boolean   '扫码双条码切换

    Public Arch(4) As MITSUBISHI_Point
    Public TimerDelay(5) As Double
    Public GetPass(5) As MITSUBISHI_Point
    Public SetPass(5) As MITSUBISHI_Point


    Public StepNO As String = "SETP0"
    Public AutoAddPhotoPoint(3) As MITSUBISHI_Point
    Public StepOK1 As Boolean
    Public StepOK2 As Boolean
    Public StepOK3 As Boolean
    Public Vision_NG As String

    '用作数据上传
    Public SNPoint_X As String = ""     '记录产品坐标X
    Public SNPoint_Y As String = ""     '记录产品坐标Y
    Public SNPoint_Z As String = ""     '记录产品坐标Z
    Public LockScrew As Integer         '记录锁附颗数
    Public BadScrew As Integer          '记录不良数量
    Public ThrowScrew As Integer        '记录当次抛钉数量
    Public StartTimeID As String        '记录开始时间
    Public EndTimeID As String          '记录结束时间
    Public ResultPASS As String         '记录结果
    Public PhotoFail As Integer         '记录拍照失败次数
    Public FloatHigh As Integer         '记录浮高次数
    Public ScrewLoose As Integer        '记录滑牙次数
    Public StatusRun As String = ""     '记录设备状态   
    Public QIZTOU As String            '记录起子头设定次数
    Public QIZTOU1 As Boolean = False
    Public QIZTOU2 As Boolean = False
    '与CCD相关
    Enum CCDRunStateInfo
        Nomal = 0
        SetError = 1 '设置序列号等错误
        Unconected = 2
        NoImage = 3 '连续两次未获取到图像
    End Enum

    ' Public FirstCCDSerNum As String = ""
    ' Public SecondCCDSerNum As String = ""

    Public FirstCCDState As Integer = 0
    Public SecondCCDState As Integer = 0
    Public ReceiveModbus(100) As Integer

    Public SendDataX(10) As Double
    Public SendDataY(10) As Double
    Public SendDataZ(10) As Double
    Public SendDataR(10) As Double
    Public Chanpin As String
    Public Flag As String = "0"
    '与报警相关
    Public Structure AlarmInfo
        Public AlarmNum As String
        Public AlarmInformation As String
    End Structure
    Public AlarmObject As New ArrayList
    'Enum AlarmInfo
    '    Nomal = 0
    '    SetError = 1 '设置序列号等错误
    '    Unconected = 2
    '    NoImage = 3 '连续两次未获取到图像
    'End Enum
    '锁附点显示程序添加
    Public Structure Point_Mark
        Dim PointX As Integer
        Dim PointY As Integer
        Dim PointResult As String
    End Structure
    Public Structure Point_Mark1
        Dim PointX As Integer
        Dim PointY As Integer

    End Structure

    Public PointMark(100) As LNLONPIC.Point_Mark
    Public CurPointMark(100) As LNLONPIC.Point_Mark
    Public ChangePointMark(100) As LNLONPIC.Point_Mark

    Public curPoint As Integer = 1 '取点编号
    Public showFailPoint As Boolean = True

    '
    Public Structure InputXY
        Public X01 As Double
        Public y01 As Double
        Public X02 As Double
        Public y02 As Double
        Public X03 As Double
        Public y03 As Double
        Public X04 As Double
        Public y04 As Double
        Public X05 As Double
        Public y05 As Double
        Public X06 As Double
        Public y06 As Double
        Public X07 As Double
        Public y07 As Double
        Public X08 As Double
        Public y08 As Double
        Public X09 As Double
        Public y09 As Double
        Public X0A As Double
        Public y0A As Double
        Public X0B As Double
        Public y0B As Double
        Public X0C As Double
        Public y0C As Double
        Public X0D As Double
        Public y0D As Double
        Public X0E As Double
        Public y0E As Double
        Public X0F As Double
        Public y0F As Double
        Public X0G As Double
        Public y0G As Double
        Public X0H As Double
        Public y0H As Double
        Public X0I As Double
        Public y0I As Double
        Public X0J As Double
        Public y0J As Double
        Public X0K As Double
        Public y0K As Double
        Public X0L As Double
        Public y0L As Double
        Public X0M As Double
        Public y0M As Double
        Public X0N As Double
        Public y0N As Double
        Public X0O As Double
        Public y0O As Double
        Public X0P As Double
        Public y0P As Double
        Public X0Q As Double
        Public y0Q As Double
        Public X0R As Double
        Public y0R As Double
        Public X0S As Double
        Public y0S As Double
        Public X0T As Double
        Public y0T As Double
        Public X0U As Double
        Public y0U As Double
        Public X0V As Double
        Public y0V As Double
        Public X0W As Double
        Public y0W As Double
        Public X0X As Double
        Public y0X As Double
        Public Sub New(ByVal s() As Double)
            X01 = s(4)
            y01 = s(5)

            X03 = s(6)
            y03 = s(7)
            X04 = s(8)
            y04 = s(9)
            X05 = s(10)
            y05 = s(11)
            X06 = s(12)
            y06 = s(13)
            X07 = s(14)
            y07 = s(15)
            X08 = s(16)
            y08 = s(17)
            X09 = s(18)
            y09 = s(19)
            X0A = s(20)
            y0A = s(21)
            X0B = s(22)
            y0B = s(23)
            X0C = s(24)
            y0C = s(25)
            X0D = s(26)
            y0D = s(27)
            X0E = s(28)
            y0E = s(29)
            X0F = s(30)
            y0F = s(31)
            X0G = s(32)
            y0G = s(33)
            X0H = s(34)
            y0H = s(35)
            X0I = s(36)
            y0I = s(37)
            X0J = s(38)
            y0J = s(39)
            X0K = s(40)
            y0K = s(41)
            X0L = s(42)
            y0L = s(43)
            X0M = s(44)
            y0M = s(45)
            X0N = s(46)
            y0N = s(47)
            X0O = s(48)
            y0O = s(49)
            X0P = s(50)
            y0P = s(51)
            X0Q = s(52)
            y0Q = s(53)
            X0R = s(54)
            y0R = s(55)
            X0S = s(56)
            y0S = s(57)
            X0T = s(58)
            y0T = s(59)
            X0U = s(60)
            y0U = s(61)
            X0V = s(62)
            y0V = s(63)
            X0W = s(64)
            y0W = s(65)
            X0X = s(66)
            y0X = s(67)

        End Sub

    End Structure
    Public Structure AlarmSetting
        Public AlarmID As String '报警编号
        Public AlarmInfo As String '报警信息
        Public Alarmprocess As String '解决办法
    End Structure
    Public Structure Count
        Public PassCount As Integer '合格产品
        Public NGCount As Integer '识别失败
        Public SCount As Integer '打螺丝失败
        Public Screwcount As Integer '锁付螺丝总数
        Public ScrewFailed1 As Integer
        Public ScrewFailed2 As Integer
        Public ScrewFailed3 As Integer
        Public ScrewFailed4 As Integer
        Public ScrewFailed5 As Integer
        Public ScrewFailed6 As Integer
        Public ScrewFailed7 As Integer
        Public ScrewFailed8 As Integer
        Public ScrewFailed9 As Integer
        Public ScrewFailed10 As Integer
        Public ScrewFailed11 As Integer
        Public ScrewFailed12 As Integer
        Public ScrewFailed13 As Integer
        Public ScrewFailed14 As Integer
        Public SFTime As Double '锁附总时长
        Public IDELTime As Double 'IDEL总时长
        Public ShutDownTime As Double 'ShutDown总时长
    End Structure
    Public Structure Count1
        Public ScrewFailed15 As Integer
        Public ScrewFailed16 As Integer
        Public ScrewFailed17 As Integer
        Public ScrewFailed18 As Integer
        Public ScrewFailed19 As Integer
        Public ScrewFailed20 As Integer
        Public ScrewFailed21 As Integer
        Public ScrewFailed22 As Integer
        Public ScrewFailed23 As Integer
        Public ScrewFailed24 As Integer
        Public ScrewFailed25 As Integer
        Public ScrewFailed26 As Integer
        Public ScrewFailed27 As Integer
        Public ScrewFailed28 As Integer
        Public ScrewFailed29 As Integer
        Public ScrewFailed30 As Integer
    End Structure
    Public Structure Count2
        Public PCSFailed As Integer '失败台数
        Public CycleTime As Integer '制程时间
        Public SuctionCount As Integer '真空异常数
        Public Height_float As Integer '浮高
    End Structure
    Public Structure Count3
        Public SkipFailed1 As Integer
        Public SkipFailed2 As Integer
        Public SkipFailed3 As Integer
        Public SkipFailed4 As Integer
        Public SkipFailed5 As Integer
        Public SkipFailed6 As Integer
        Public SkipFailed7 As Integer
        Public SkipFailed8 As Integer
        Public SkipFailed9 As Integer
        Public SkipFailed10 As Integer
        Public SkipFailed11 As Integer
        Public SkipFailed12 As Integer
        Public SkipFailed13 As Integer
        Public SkipFailed14 As Integer
    End Structure
    Public Structure Count4
        Public SkipFailed15 As Integer
        Public SkipFailed16 As Integer
        Public SkipFailed17 As Integer
        Public SkipFailed18 As Integer
        Public SkipFailed19 As Integer
        Public SkipFailed20 As Integer
        Public SkipFailed21 As Integer
        Public SkipFailed22 As Integer
        Public SkipFailed23 As Integer
        Public SkipFailed24 As Integer
        Public SkipFailed25 As Integer
        Public SkipFailed26 As Integer
        Public SkipFailed27 As Integer
        Public SkipFailed28 As Integer
        Public SkipFailed29 As Integer
        Public SkipFailed30 As Integer
    End Structure
    Public Structure ScrewPara
        Public PointCount As Integer '螺丝颗数
        Public ScrewSN As String '螺丝SN
        Public FloatMin As String '浮高最小值
        Public FloatMax As String '浮高最大值
        'Public PhotoSU As String '螺丝长度
    End Structure
    Public Structure returnXY
        Public X1 As Double
        Public Y1 As Double
        Public X2 As Double
        Public Y2 As Double
        Public X3 As Double
        Public Y3 As Double
        Public X4 As Double
        Public Y4 As Double
        Public X5 As Double
        Public Y5 As Double
        Public X6 As Double
        Public Y6 As Double
        Public X7 As Double
        Public Y7 As Double
        Public X8 As Double
        Public Y8 As Double
        Public X9 As Double
        Public Y9 As Double
        Public X10 As Double
        Public Y10 As Double
        Public X11 As Double
        Public Y11 As Double
        Public X12 As Double
        Public Y12 As Double
        Public X13 As Double
        Public Y13 As Double
        Public X14 As Double
        Public Y14 As Double
        Public X15 As Double
        Public Y15 As Double
        Public X16 As Double
        Public Y16 As Double
        Public X17 As Double
        Public Y17 As Double
        Public X18 As Double
        Public Y18 As Double
        Public X19 As Double
        Public Y19 As Double
        Public X20 As Double
        Public Y20 As Double
        Public X21 As Double
        Public Y21 As Double
        Public X22 As Double
        Public Y22 As Double
        Public X23 As Double
        Public Y23 As Double
        Public X24 As Double
        Public Y24 As Double
        Public X25 As Double
        Public Y25 As Double
        Public X26 As Double
        Public Y26 As Double
        Public X27 As Double
        Public Y27 As Double
        Public X28 As Double
        Public Y28 As Double
        Public X29 As Double
        Public Y29 As Double
        Public X30 As Double
        Public Y30 As Double
        Public Function read() As String()
            Dim s(60) As String
            s(0) = X1
            s(1) = Y1
            s(2) = X2
            s(3) = Y2
            s(4) = X3
            s(5) = Y3
            s(6) = X4
            s(7) = Y4
            s(8) = X5
            s(9) = Y5
            s(10) = X6
            s(11) = Y6
            s(12) = X7
            s(13) = Y7
            s(14) = X8
            s(15) = Y8
            s(16) = X9
            s(17) = Y9
            s(18) = X10
            s(19) = Y10
            s(20) = X11
            s(21) = Y11
            s(22) = X12
            s(23) = Y12
            s(24) = X13
            s(25) = Y13
            s(26) = X14
            s(27) = Y14
            s(28) = X15
            s(29) = Y15
            s(30) = X16
            s(31) = Y16
            s(32) = X17
            s(33) = Y17
            s(34) = X18
            s(35) = Y18
            s(36) = X19
            s(37) = Y19
            s(38) = X20
            s(39) = Y20
            s(40) = X21
            s(41) = Y21
            s(42) = X22
            s(43) = Y22
            s(44) = X23
            s(45) = Y23
            s(46) = X24
            s(47) = Y24
            s(48) = X25
            s(49) = Y25
            s(50) = X26
            s(51) = Y26
            s(52) = X27
            s(53) = Y27
            s(54) = X28
            s(55) = Y28
            s(56) = X29
            s(57) = Y29
            s(58) = X30
            s(59) = Y30
            Return s
        End Function
        Public Sub New(ByVal s() As Double)
            X1 = s(0)
            Y1 = s(1)
            X2 = s(2)
            Y2 = s(3)
            X3 = s(4)
            Y3 = s(5)
            X4 = s(6)
            Y4 = s(7)
            X5 = s(8)
            Y5 = s(9)
            X6 = s(10)
            Y6 = s(11)
            X7 = s(12)
            Y7 = s(13)
            X8 = s(14)
            Y8 = s(15)
            X9 = s(16)
            Y9 = s(17)
            X10 = s(18)
            Y10 = s(19)
            X11 = s(20)
            Y11 = s(21)
            X12 = s(22)
            Y12 = s(23)
            X13 = s(24)
            Y13 = s(25)
            X14 = s(26)
            Y14 = s(27)
            X15 = s(28)
            Y15 = s(29)
            X16 = s(30)
            Y16 = s(31)
            X17 = s(32)
            Y17 = s(33)
            X18 = s(34)
            Y18 = s(35)
            X19 = s(36)
            Y19 = s(37)
            X20 = s(38)
            Y20 = s(39)
            X21 = s(40)
            Y21 = s(41)
            X22 = s(42)
            Y22 = s(43)
            X23 = s(44)
            Y23 = s(45)
            X24 = s(46)
            Y24 = s(47)
            X25 = s(48)
            Y25 = s(49)
            X26 = s(50)
            Y26 = s(51)
            X27 = s(52)
            Y27 = s(53)
            X28 = s(54)
            Y28 = s(55)
            X29 = s(56)
            Y29 = s(57)
            X30 = s(58)
            Y30 = s(59)
        End Sub
    End Structure
    Public Structure PsetSetting    '放置点补偿
        Public XPosCompensate As Double  'X补偿
        Public YPosCompensate As Double  'Y补偿
        Public ZPosCompensate As Double  'Z补偿
        Public RPosCompensate As Double  'R补偿
    End Structure
    'Public Structure MachineInfo
    '    Public Machine_Site As String
    '    Public Machine_Plant As String  '厂别
    '    Public Machine_Dept As String   '车间
    '    Public Machine_LineID As String '线别
    '    Public Machine_MIP As String    'IP
    '    Public Machine_MModel As String '型号
    '    Public Machine_MName As String  '设备名
    '    Public Machine_MNO As String    '设备NO
    '    Public Machine_MSN As String    '设备SN
    '    Public Machine_KeyType As String  '扫码用KeyInfoType
    '    Public Machine_StageCode As String '扫码用StageCode
    'End Structure
    Public Structure NameAndSN
        Public ChanpinName As String
        Public ChanpinSN As String
    End Structure
    Public Class SFCSByReal
        Public evt_type As String = "byreal"   '数据分类
        Public evt_dt As Long
        Public evt_puBy As String = "nifi" '
        Public Site As String '
        Public Plant As String  '厂别
        Public Dept As String   '车间
        Public Line As String '线别
        Public MachineName As String    'IP
        Public MachineModel As String '型号
        Public MachineSN As String  '设备名
        Public MachineNO As String    '设备NO
        Public MachineIP As String    '设备SN
        ' Public MachineKeyType As String  '扫码用KeyInfoType

        Public Model As String
        Public Program As String
        Public Status As String
        Public Errcode As String
    End Class
    Public Class SFCSByPCS
        Public evt_type As String = "bypcs"  '数据分类
        Public evt_dt As Long
        Public evt_pubBy As String = "nifi"
        Public Site As String
        Public Plant As String  '厂别
        Public Dept As String   '车间
        Public Line As String '线别
        Public MachineName As String    'IP
        Public MachineModel As String '型号
        Public MachineSN As String  '设备名
        Public MachineNO As String    '设备NO
        Public MachineIP As String    '设备SN
        ' Public MachineKeyType As String  '扫码用KeyInfoType
        ' Public Time As Long
        Public Model As String
        Public Program As String
        Public OperatorID As String
        Public USN As String
        Public TotalPoint As Integer
        Public NGPoint As Integer
        Public SkipPoint As Integer
        Public SkipPointPICNO As String
        Public TotalInput As Integer
        Public OKInput As Integer
        Public NGInput As Integer
        Public YieldRate As Double
        '  Public OperatorID As String '20170810 换位置
        Public CameraoffsetX As Double
        Public CameraoffsetY As Double
        Public CameraoffsetUOM As String
        Public ScrewdriverSpeed As Double   '无
        Public ScrewdriverSpeedUOM As String = "r/min"
        Public AxisSpeedX As Double '无
        Public AcceTimeX As Double '无
        Public AxisSpeedY As Double '无
        Public AcceTimeY As Double '无
        Public AxisSpeedZ As Double '无
        Public AcceTimeZ As Double '无
        Public AxisSpeedUOM As String = "mm/s"
        Public AcceTimeUOM As String = "ms"
        Public StartTime As String
        Public EndTime As String
        Public CycleTime As Double
        Public IsOK As Integer = 1 '20170810 新增
        Public NGPICNO As String '20170810 新增
        Public Points() As PointData
        Public Sub New(ByVal Size As UShort) 'Size就是传入的数组的大小
            Points = New PointData(Size) {}
            For i = 0 To Size
                Points(i).Result = "skip"
                Points(i).NGReson = Nothing
            Next
        End Sub
        Public Structure PointData
            Public NO As Integer
            Public Result As String
            Public NGReson As String
            Public CCDCenterX1 As Double
            Public CCDCenterY1 As Double
            Public CCDCenterX2 As Double
            Public CCDCenterY2 As Double
            Public ScrewPositionX As Double
            Public ScrewPositionY As Double
            Public ScrewPositionZ As Double
            Public ScrewPositionR As Double
        End Structure
    End Class

    Public XY As InputXY
    Public Pset(29) As PsetSetting
    Public Pget(6) As PsetSetting
    Public myalarm(50) As AlarmSetting
    Public Todaycount As Count
    Public Todaycount1 As Count1
    Public Todaycount2 As Count2
    Public Todaycount3 As Count3
    Public Todaycount4 As Count4
    'new add for UpLoadData

    Public CurNameAndSN As NameAndSN    '已加载产品名及SN
    Public NewNameAndSN As NameAndSN    '新扫码产品名及SN
    'Public MachineInfo1 As MachineInfo  '设备信息
    Public DataByPCS As SFCSByPCS = New SFCSByPCS(30) '生产产品数据
    'Public DataByReal As SFCSByReal = New SFCSByReal '实时上传数据
    'Public NullDataByReal As SFCSByReal = New SFCSByReal '实时上传数据
    Public initOK_flag As Boolean = False '初始化完成flag
    'Public UpLoadComplete_flag As Boolean = False '上传完成flag
    'Public MachineInfo_flag As Boolean = True '设备信息加载完成flag

    'Public MachineStatus As String  'Machine ON/OFF/IDLE/Run/Shutdown
    'Public MachineErrCode As String  'Machine Error Code,异常code
    Public CurScrewPara As ScrewPara
    Public ScrewOKCount As Integer    '设备螺丝总颗数
    Public CurPointNO As Integer    '当前数据螺丝号
    'Public StartTime As Double
    'Public EndTime As Double

    Public ZaxisPls(30) As Double    'Z相脉冲设定
    Public ZaxisCheckUSE As Boolean    '启用Z相检测

    Public OldDataByReal As String = ""
    Public Suction As String
    Public newset(7) As Boolean
    Public Selected As Integer = 0
    Public SPString As String = ""
    Public OldSPString As String = ""
    Public file_num_count As Integer = FreeFile()
    Public file_num_count1 As Integer = FreeFile()
    Public file_num_count2 As Integer = FreeFile()
    Public file_num_count3 As Integer = FreeFile()
    Public file_num_count4 As Integer = FreeFile()
    Public file_set As Integer = FreeFile()
    Public NumberOfAlarmArray As Integer
    Public NumberOfPSetArray As Integer = 30
    Public NumberOfSet As Integer = 8
    Public NumberOfGet As Integer = 4
    Public Input As String = ""
    Public SC_flag As String
    Public SN_Socket As Socket
    Public SecondRobotProduct As String = ""
    Public ThirdRobotProduct As String = ""
    Public FourthRobotProduct As String = ""
    Public SendProduct As String = ""
    Public NoProduct As Boolean = False
    Public Screw As String
    Public PATH_Xlsx As String = "Base_SN.xlsx"
    Public ADD_Screw_Count As Double
    Public Retry_Times As Double
    Public Clear_Time As Double
    Public DLLFirst As String
    Public DLLSecond As String
    Public Product_lenth As String
    Public SQL_Excel_Name1 As String
    Public SQL_Excel_Name2 As String
    Public PU_Name As String
    Public Skip As String

    Public Angle As Short
    Public Angle1 As Double
    Public Angle2 As Double

    Public Torsion As Short
    Public Torsion1 As Double
    Public Torsion2 As Double

    Public Access_enable As Boolean

    Public RotationAngleo As Short
    Public RotationAngleo1 As Short

    Public RunningCCD As Boolean
    Public Ccd1AreaMinSet As Double
    Public Ccd1AreaMaxSet As Double

    Public Ccd2AreaMinSet As Double
    Public Ccd2AreaMaxSet As Double

    Friend WithEvents TCmbPro As System.Windows.Forms.ToolStripComboBox
    'Public UploadPath As String = My.Application.Info.DirectoryPath & "\数据上传程序"
    Public DebugPath As String = My.Application.Info.DirectoryPath

    '三菱机器人
    Public lRobotID As Integer
    Public ServoON As String
    Public TOOL() As String
    Public Receive_IOValue(4) As String
    Public TBcheck_NO As Integer
    Public FL_FLG(2) As Integer '姿态标志
    Public Motor_dly As Double
    Public InputIO_Value(33) As Integer
    Public OutputIO_Value(33) As Integer
    Public IO_ValueHx As String
    Public Robot_Connected As Boolean

    Public SN_CheckMode As Integer

    '数据上传
    Public Class IOT_Machine_Info    '设备信息
        Public Device_type As String  '设备的类型
        Public Manufacturer As String  '厂商
        Public Device_Code As String  '设备型号
        Public Device_id As String  '机台号
        Public Line As String  '线别
        Public IP As String  'IP
        Public Family As String '机型
        Public Station As String '站别
        Public Fixture As String '治具编号
    End Class

    Public Class IOT_Machine_Status
        Inherits IOT_Machine_Info
        Public Status As String  '状态  0运行 1 等待 2 宕机 3 XCPro开机  4 XCPro关机
        Public ErrorCode As String  '错误代码
        Public CreateTime As String
        Public UpdateTime As String
    End Class

    Public Class IOT_FILATURE_MainInfo    '主要信息
        Inherits IOT_Machine_Info
        Public NoteBook_Qty As String  '笔记本数
        Public Screw_Qty As String  '总螺丝数
        Public SF_Fail_Qty As String  '锁附异常总数
        Public SB_Fail_Qty As String  '识别异常总数
        Public Yield As String  '良率
        Public RunTime As String  '开机时间
        Public SF_Time As String  '锁附总时长
        Public IDEL As String  'IDEL总时长      
        Public UpdateTime As String
    End Class

    Public Class IOT_FILATURE_SN_Info    'SN信息
        Inherits IOT_Machine_Info
        Public Family As String  '机型
        Public SN As String  'SN
        Public SF_Cdt_Begin As String  '锁附开始时间
        Public SF_Cdt_End As String  '锁附结束时间
        Public Screw_Qty As String  '锁附螺丝数
        Public SF_Fail_Qty As String  '锁附异常数
        Public SB_Fail_Qty As String  '识别异常数
        Public Status As String  '状态（PASS/RPASS/Fail）
    End Class

    Public Class IOT_FILATURE_SN_Detail    'SN详情
        Public SN As String  'SN
        Public Screw_A1 As String  '锁附坐标值
        Public TorqueValue As String  '扭力值
        Public Status As String  '状态（PASS/FAIL）
        Public ErrType As String  '异常代码
        Public SF_Cdt_Begin As String  '锁附开始时间
        Public SF_Cdt_End As String  '锁附结束时间
        Public NumOfScrew As String '第几颗螺丝
    End Class

    Public machineInfo As IOT_Machine_Info = New IOT_Machine_Info '设备信息
    Public machineInfoStatus As IOT_Machine_Status = New IOT_Machine_Status '设备状态信息
    Public mainInfo As IOT_FILATURE_MainInfo = New IOT_FILATURE_MainInfo '生产数据信息
    Public SNInfo As IOT_FILATURE_SN_Info = New IOT_FILATURE_SN_Info 'SN信息
    Public SNDetail As IOT_FILATURE_SN_Detail = New IOT_FILATURE_SN_Detail 'SN详情
    Public HistoryStatus As ArrayList = New ArrayList '历史上传状态信息
    Public Tcmb_Queue As Queue = New Queue '产品队列
    'Public SN_Queue As Queue = New Queue 'SN队列
    Public SN_Queue As Queue(Of ProdInfo) = New Queue(Of ProdInfo)
    Public showSNQueueFlag As Boolean '显示SN队列
    Public Can_Barcode As Boolean = False  '允许扫码标志
    Public UploadPath As String = My.Application.Info.DirectoryPath & "\数据上传程序"
    Public MySQLIP As String = "" '数据库IP
    Public MySQLUserName As String = "" '数据库登录用户名
    Public MySQLPassWord As String = "" '密码
    Public MySQLDataBase As String = "" '数据库名称
    Public FTPUploadPath1 As String = ""
    Public StateFreTime As String = "" '状态上传频率
    Public ProductFreTime As String = "" '生产数据上传频率
    Public startTime As DateTime = DateTime.MinValue
    Public startTime_SC As DateTime = DateTime.MinValue
    Public endTime As DateTime = DateTime.MinValue
    Public SF_Fail_Qty_Single As Integer = 0
    Public SB_Fail_Qty_Single As Integer = 0
    Public shutDownTime As Double = 0 '异常时间
    Public startTime_SD As DateTime = DateTime.MinValue
    Public endTime_SD As DateTime = DateTime.MinValue
    Public line As String = "" '参数设置line站号
    Public keycode As String = "" '参数设置keycode
    Public Paramset_num As Integer = FreeFile()
    'Public lRobotID As Integer '机器人ID
    'Public OutputIO_Value(33) As Integer
    'Public Receive_IOValue(4) As String
    Public isFail As Boolean

    Public PLC_brands As String = "三菱_FX5U"

    Public Globalfunc As FuncPortal.FuncLNLON = New FuncPortal.FuncLNLON
    'Public PLC_brands As String = "西门子_200_smart"
    Public SP1_SN1 As String
    Public SP1_SN2 As String
    Public SP1_cisu As Integer = 0

    Public Motor_flag As Boolean '机器人伺服启用标志

    Public Y轴_最小偏差限制 As Double = 0
    Public Y轴_最大偏差限制 As Double = 0

    Public writeOK As Boolean
    Public REPLY_MES As String

    Public PLCFlag As Boolean = False

    Public JQStart As String = ""
    Public JQLength As Integer = 0

    Public newsetM(5) As Boolean
    Public IPAddm(5) As String
    Public IPAddnum As String
    Public Bfalge As Boolean
End Module
